//
//  ARSearchBar.h
//  MySearchBar
//
//  Created by August on 14-7-28.
//  Copyright (c) 2014年 August. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface QWSearchBarTextField : UITextField

//替代原生🔍图标
@property (nonatomic, strong) UIImage *leftImage;
//右边清楚按钮的图标∫
@property (nonatomic, strong) UIImage *clearButtonImage;
//placeholder的颜色
@property (nonatomic, strong) UIColor *placeholderColor;

@end


@class QWSearchBar;
@protocol QWSearchBarDelegate <NSObject>

@optional
- (void)QWSearchBar:(QWSearchBar *)searchBar textDidChange:(NSString *)searchText;
- (BOOL)QWSearchBar:(QWSearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0);

- (BOOL)QWSearchBarShouldBeginEditing:(QWSearchBar *)searchBar;
- (void)QWSearchBarDidBeginEditing:(QWSearchBar *)searchBar;
- (BOOL)QWSearchBarShouldEndEditing:(QWSearchBar *)searchBar;
- (void)QWSearchBarDidEndEditing:(QWSearchBar *)searchBar;

- (BOOL)QWSearchBarShouldClear:(QWSearchBar *)searchBar;
- (void)QWSearchBarSearchButtonClicked:(QWSearchBar *)searchBar;

@end

@interface QWSearchBar : UIView <UITextFieldDelegate>

@property (nonatomic, weak) id<QWSearchBarDelegate> delegate;
@property (nonatomic, strong) QWSearchBarTextField *textField;

@property (nonatomic, assign) CGFloat leadingSpace;
@property (nonatomic, assign) CGFloat topSpace;

- (BOOL)becomeFirstResponder;
- (BOOL)resignFirstResponder;

@property(nonatomic, copy) NSString *text;
@property(nonatomic, copy) NSString *placeholder;
@property(nonatomic, strong) UIFont *font;
@property(nonatomic, strong) UIColor *textColor;
@property(nonatomic, strong) UIColor *searchBarBackgroundColor;

@property(nonatomic) UIKeyboardType keyboardType;
@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
@property(nonatomic) UITextFieldViewMode clearButtonMode;

@property (nonatomic, strong) UIImage *leftImage;
@property (nonatomic, strong) UIImage *clearButtonImage;
@property (nonatomic, strong) UIColor *placeholderColor;

@end